package customer.zspt.cn.customer.components.order;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.TextView;

import com.google.gson.Gson;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;

import java.util.ArrayList;
import java.util.List;

import customer.zspt.cn.customer.Adapter.OrderVpAdapter;
import customer.zspt.cn.customer.R;
import customer.zspt.cn.customer.components.order.orderVp.BaseVpItem;
import customer.zspt.cn.customer.components.order.orderVp.OrderFirstVpItem;
import customer.zspt.cn.customer.components.order.orderVp.OrderSecondVpItem;
import customer.zspt.cn.customer.components.order.orderVp.OrderThirdVpItem;
import customer.zspt.cn.customer.bean.OrderMsgDao;

/**
 * Created by Administrator on 2018/7/14 0014.
 */

public class order_view  extends Activity implements View.OnClickListener{
    private int orderId;
    private String ordercontent;
    @ViewInject(R.id.from_line)
    private View from_line;
    @ViewInject(R.id.state_line)
    private View state_line;
    @ViewInject(R.id.content_line)
    private View content_line;
    @ViewInject(R.id.order_content)
    private TextView order_content;
    @ViewInject(R.id.order_state)
    private TextView order_state;
    @ViewInject(R.id.order_from)
    private TextView order_from;
    @ViewInject(R.id.order_showVP)
    private ViewPager order_showVP;
    private String guserid;

    private List<BaseVpItem> order_view_childLs =  new ArrayList<>();
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.order_view);
        ViewUtils.inject(this);
        orderId = Integer.parseInt(getIntent().getStringExtra("orderId"));
        ordercontent = getIntent().getStringExtra("ordercontent");
        guserid = getIntent().getStringExtra("guserid");
        pushData();
        initListener();
    }
    private void setLineState(int position)
    {
        order_content.setTextColor(position==0?getResources().
                getColor(R.color.green):getResources().getColor(R.color.textColor));
        order_state.setTextColor(position==1?getResources().
                getColor(R.color.green):getResources().getColor(R.color.textColor));
        order_from.setTextColor(position==2?getResources().
                getColor(R.color.green):getResources().getColor(R.color.textColor));
        content_line.setVisibility(position==0?View.VISIBLE:View.GONE);
        state_line.setVisibility(position==1?View.VISIBLE:View.GONE);
        from_line.setVisibility(position==2?View.VISIBLE:View.GONE);
        order_showVP.setCurrentItem(position);
    }
    private void initListener() {
        order_content.setOnClickListener(this);
        order_state.setOnClickListener(this);
        order_from.setOnClickListener(this);
        order_showVP.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }
            @Override
            public void onPageSelected(int position) {
                   switch (position)
                   {
                       case 0:
                           setLineState(0);
                           break;
                       case 1:
                           setLineState(1);
                           break;
                       case 2:
                           setLineState(2);
                           break;
                   }
            }
            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }
    private void pushData() {
        try{
            Gson gson = new Gson();
            OrderMsgDao.OrderMsg orderMsg = gson.fromJson(ordercontent, OrderMsgDao.OrderMsg.class);
            order_view_childLs.add(new OrderFirstVpItem(this,orderMsg,guserid));
            order_view_childLs.add(new OrderSecondVpItem(this,orderMsg,guserid,orderId));
            order_view_childLs.add(new OrderThirdVpItem(this,orderMsg,guserid));
            OrderVpAdapter adapter = new OrderVpAdapter(this,order_view_childLs);
            order_showVP.setAdapter(adapter);
            order_view_childLs.get(0).initData();
        }
        catch (Exception e)
        {
             e.printStackTrace();
        }
    }
    @Override
    public void onClick(View v) {
            switch (v.getId())
            {
                case R.id.order_content:
                    setLineState(0);
                    break;
                case R.id.order_state:
                    setLineState(1);
                    break;
                case R.id.order_from:
                    setLineState(2);
                    break;
            }
    }


}
